#include <iostream>
#include "httplib.h"
using namespace httplib;
void Hello(const Request &req, Response &rsp)
{
    rsp.set_content("hello world!", "text/plain");
    rsp.status = 200;
}
void Numbers(const Request &req, Response &rsp)
{
    auto numbers = req.matches[1];
    rsp.set_content(numbers, "text/plain");
    rsp.status = 200;
}
void Multipart(const Request &req, Response &rsp)
{
   auto ret=req.has_file("file");
   if(ret==false)
   {
    std::cout<<"not file upload\n";
    rsp.status=400;
    return ;
   }
   const auto& file=req.get_file_value("file");
   rsp.body.clear();
   rsp.body=file.filename;
   rsp.body+="\n";
   rsp.body+=file.content;
   rsp.set_header("Content-Type","text/plain");
   rsp.status=200;
   return;

}
/**
 * 浏览器访问时使用云服务器的公网IP+端口号
 * 
*/
int main()
{

    Server server;
    server.Get("/hi", Hello);
    server.Get(R"(/numbers/(\d+))", Numbers);
    server.Post("/mutipart", Multipart);
    server.listen("0.0.0.0", 7777);
    return 0;
}